<template>
	<view>
		<view class="search-box">
			<view class="search">
				<i class="iconfont iconicon_sousuo icon" ></i>
				<input type="text" value="" placeholder="请输入关键字" maxlength="15" @confirm="confirm" />
			</view>
		</view>
		
		<view class="head">
			<image src="https://friend.tanshishang.cn/assets/img/friend.jpg" mode=""></image>
		</view>
		
		<view class="items" v-for="(item,index) in list" :key="index" @tap="toDetail(item)" >
			<view class="avatar">
				<view class="avatar-img">
					<image :src="item.avatar" mode=""></image>
				</view>
				<view></view>
			</view>
			<view class="info">
				<view class="info-title">{{ item.title }}</view>
				<view class="info-content">
					<view class="info-content-left">
						<i class="iconfont iconicon_dingwei icons" style="color: #0091FF;"></i>
						<text>{{ doStr(item.place) }}</text>
					</view>
					<view class="info-content-right">
						<i style="margin-left: 10rpx;color: #0091FF;" class="iconfont iconicon_riqi icons"></i>
						<text>{{ item.engagementtime }}</text>
					</view>
				</view>
				<view class="num">
					报名情况:
					<view>男<text>{{ item.addman }}</text>/{{ item.man }}</view>
					<view>女<text>{{ item.addwoman }}</text>/{{ item.woman }}</view>
				</view>
			</view>
			<view class="status" style="background-color: #FE4392;color: #FFFFFF;" v-if="item.statusStr==0" >未开始</view>
			<view class="status" style="background-color: #0091FF;color: #FFFFFF;" v-if="item.statusStr==1" >进行中</view>
			<view class="status" style="background-color: #D8D8D8;color: #999999;" v-if="item.statusStr==2" >已结束</view>
			<view class="status" style="background-color: #D8D8D8;color: #999999;" v-if="item.activestatus==1">已结束</view>
		</view>
		
		
		<view class="btn" @tap="fabu()" >十</view>
		
		
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex'
	export default {
		computed: {
			...mapState(['token'])
		},
		data() {
			return {
				list:[],
				isVip:false,
				page:1,
				pages:null,
				keyword:''
			};
		},
		//分享给个人
		onShareAppMessage() {
			return {
				title: '青年交友',
				imageUrl:'https://friend.tanshishang.cn/assets/img/shareImg.png',
				path:'/pages/index/index'
			}
		},
		onLoad() {
			//获取数据
			// this.getData()
			
		},
		onShow() {
			this.page = 1;
			this.pages = null;
			this.list = [];
			this.keyword = '';
			this.getData();
		},
		//下拉刷新
		onPullDownRefresh() {
			console.log('下拉刷新');
			setTimeout(() => {
				this.page = 1;
				this.pages = null;
				this.list = [];
				this.keyword = '';
				this.getData();
				uni.stopPullDownRefresh();
			}, 1000)
		},
		//上拉加载
		onReachBottom() {
			console.log('触发上拉加载');
			if(this.page < this.pages){
				this.page++;
				this.getData();
			}else{
				uni.showToast({
					title:'到底啦!',
					icon:'none'
				})
			}
		},
		methods:{
			//获取数据
			async getData(){
				try{
					let params = { token:this.token,page:this.page,keyword:this.keyword };
					let res = await this.$request.request.get('/api/engagement/index',params)
					console.log(res);
					if(res.code ==200){
						this.list = this.list.concat(res.data.list);
						this.isVip = res.data.isVip;
						this.pages = res.data.pages;
					}
				}catch(err){
				    this.$request.error(err,this)
				}
			},
			//搜索
			confirm(e){
				this.keyword = e.detail.value;
				console.log(this.keyword);
				
				this.list = [];
				this.page = 1;
				this.pages = null;
				this.getData();
			},
			//前往详情
			toDetail(e){
				uni.navigateTo({
					url:"dateDetail?id="+e.id
				})
			},
			//点击发布
			fabu(){
				if(this.isVip){
					uni.navigateTo({
						url:'releaseDate',
					})
				}else{
					uni.showModal({
						title: '温馨提醒',
						content: '您还未开通VIP，仅有VIP才能进行此项操作',
						showCancel: true,
						confirmText: '开通VIP',
						success: (res) => {
							// console.log(res);
							if (res.confirm) {
								this.toPay();
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
							
						}
					});
				}
			},
			//支付
			async toPay() {
				
				try {
					let params = {
						token: this.token
					};
					let res = await this.$request.request.post('/api/user/renewal', params)
					console.log(res);
					if (res.code == 200) {
						//跳转支付页
						uni.navigateTo({
							url: '/pages/my/payInfo?orderNo=' + res.data.orderNo + '&price=' + res.data.price
						})
					}
				} catch (err) {
					this.$request.error(err, this);
				}
			},
			//位置切割
			doStr(e){
				if(e){
					let arr = e.split('-');
					if(arr.length>1){
						return arr[1]
					}else{
						return arr[0]
					}
				}
			}
		}
	}
</script>

<style lang="scss">
@import 'dateCircle.scss'
</style>
